const nodemailer = require('nodemailer') // 发送邮件模块
const {
    default: Axios
} = require('axios') // 获取自动文字模块
const schedule = require('node-schedule') // 定时发送模块

// 发送邮件函数
async function sendMail(text) {
    var user = 'yaoxuu@qq.com' // 发送者邮箱
    var pass = 'jwwwwyedcsvvdicd' // QQ邮箱授权码
    var to = '1710252113@vip.henu.edu.cn' // 接受者邮箱
    let transporter = nodemailer.createTransport({
        host: 'smtp.qq.com',
        port: 587,
        secure: false,
        auth: {
            user: user,
            pass: pass
        }
    })
    let info = await transporter.sendMail({
        from: `QQ_Mail<${user}>`,
        to: `Henu_Mail<${to}>`,
        subject: `hello world`,
        text: text
    })
    console.log('send success!')
}

// 获取自动生成文字函数
function getCHP() {
    var url = 'https://chp.shadiao.app/api.php'
    return Axios.get(url)
}

// 设置定时发送时间
schedule.scheduleJob({
    hour: 23,
    minute: 57
}, function () {
    console.log("启动! 准备发送中... " + new Date())
    getCHP().then(res => {
        sendMail(res.data)
        console.log(res.data)
        // return res
    })
    // sendMail('hello')
})
// sendMail('hello')

getCHP().then(res => {
    console.log(res.data)
    // return res
})